package com.far.game.xiuzhen.gm.web.api.admin;


import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSON;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.far.game.xiuzhen.common.database.entity.Partner;
import com.far.game.xiuzhen.common.database.entity.Skills;
import com.far.game.xiuzhen.common.database.entity.UserPartner;
import com.far.game.xiuzhen.gm.web.BaseController;
import com.far.game.xiuzhen.service.IPartnerService;
import com.far.game.xiuzhen.service.IUserPartnerService;
import com.far.tools.net.http.ReqParamWrapper;
import com.far.tools.net.http.transfer.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mike
 * @since 2022-07-15
 */
@Api(tags = "用户伙伴层")
@RestController
@RequestMapping("/api/admin/user/partner")
public class UserPartnerController extends BaseController {

    @Autowired
    @Qualifier("userPartnerServiceImpl")
    private IUserPartnerService iUserPartnerService;


    /**
     * 用户角色表数据新增
     */

    @ApiOperation(value = "用户伙伴新增", notes = "用户伙伴表数据新增")
    @PostMapping(value = "user-partner-add")
    private ResultData<String> userPartnerAdd(@RequestBody UserPartner userPartner) {
        userPartner.setCreateBy(this.getVisitor().getUserName());
        userPartner.setUpdateBy(this.getVisitor().getUserName());
        if (iUserPartnerService.save(userPartner)) {
            return ResultData.ok("添加成功");
        }
        return ResultData.error("添加失败");
    }

    /**
     * 用户角色表数据更新
     */
    @ApiOperation(value = "用户伙伴更新", notes = "更新用户伙伴数据")
    @PostMapping(value = "user-partner-update")
    private ResultData<String> userPartnerUpdate(@RequestBody UserPartner userPartner) {
        userPartner.setUpdateBy(this.getVisitor().getUserName());
        if (iUserPartnerService.updateById(userPartner)) {
            return ResultData.ok("更新成功");
        }
        return ResultData.error("更新失败");
    }

    /**
     * 用户角色表数据删除
     */
    @ApiOperation(value = "用户伙伴删除", notes = "删除用户伙伴数据")
    @ApiImplicitParam(name = "tid", value = "ID", required = true, paramType = "query", dataType = "Integer")
    @GetMapping(value = "user-partner-remove")
    private ResultData<String> serversRemove(@RequestParam("tid") Integer tid) {
        if (iUserPartnerService.removeById(tid)) {
            return ResultData.ok("删除成功");
        }
        return ResultData.error("删除失败");
    }

    /**
     * 用户角色表数据查询
     */
    @ApiOperation(value = "用户伙伴查询", notes = "查询用户伙伴数据")
    @PostMapping(value = "query")
    private ResultData<IPage<UserPartner>> Query(@RequestBody ReqParamWrapper<UserPartner, String> reqParamWrapper) {
        IPage<UserPartner> iPage = reqParamWrapper.pageLists(iUserPartnerService);
        if (iPage.getRecords().size() == 0) {
            return ResultData.error("暂无数据");
        }
        return ResultData.ok(iPage);
    }


}

